<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
    function onstsubmit()
    {
        $('#printform').modal('hide');
        $('#attributeform').submit();
    }
	function outcsvsubmit()
	{
		$("#yanwenexpressform").modal('hide');
		$("#outcsvform").submit();	
	}
	function savecsv()
	{
		$('#yanwenexpressform').modal('show');
	}
    function changstatusPro(t)
    {
        var str = selectallpro();
        if(str !=false)
        {
            if(confirm("确认将选中的订单，修改状态?"))
            {
                $.post("/factory/ajaxbutton", {"op": "changstatus","id":str,"st":t},
                        function(data){
                            if(data==200)
                            {
                                document.location.href = "/factory/orderlist";
                                return;
                            }

                            return;
                        },"json");
            }
        }
    }
    function addPrint() {
        if(confirm("确认打印选中的订单，一旦打印将会自动标注打印标记?")){
        }else{
            return false;
        }
        var obj=document.getElementsByName('ppid[]');
        var chk_value =[];
        var s= "";
        for (var i=0;i<obj.length;i++)
        {
            if(obj[i].checked) s+=obj[i].value+','; //如果选中，将value添加到变量s中
        }
        if(s){
            var url ='/batchfactoryorder/ajaxbutton?op=orderPrint&param='+s;
            //location.href= url;
            window.open(url);
        }else{
            alert("请选择需要打印的订单!");return ;
        }

    }
    function updfactorystatus(id,status){
        $.post("/productprint/updfactorystatus",{id:id,status:status},function(data){
            //alert(data.code);return false;
            if(data.code)
            {
                alert(data.msg);
                if(data.code==1){
                    $('#showstatus').html('已完成');
                }else{
                    $('#showstatus').html('已作废');
                }
                location.reload();
            }else{
                alert(data.msg);return false;
            }
        },"json");
    }
    function searchEmployee() {
        var str_workers = "<option value=''>---请选择---</option>";
        var str_caijian = "<option value=''>---请选择---</option>";
        var factory_id = $("#search_factorys").val();
        if(factory_id){
        }else{
            $("#search_workers").html("<option value=''>---请选择---</option>");
            $("#search_caijian").html("<option value=''>---请选择---</option>");
            return false;
        }
        $.post("/batchfactoryorder/searchEmployee",{factory_id:factory_id},function(data){
            //alert(data.code);return false;
            if(data.code)
            {

                for (var i=0;i<data.workers.length;i++)
                {
                    str_workers += "<option value='"+data.workers[i].id+"'>"+data.workers[i].name+"</option>";
                }
                //裁剪人员
                for (var i=0;i<data.caijian.length;i++)
                {
                    str_caijian += "<option value='"+data.caijian[i].id+"'>"+data.caijian[i].name+"</option>";
                }
                $("#search_workers").html(str_workers);
                $("#search_caijian").html(str_caijian);





            }else{
                //alert("失败!");return false;
            }
        },"json");
    }
//批量修改订单状态
 function updOrderStatus(status) {
     var str = selectallpro();
     if(str !=false)
     {
         if (status == 1) {
             var message = "是否确认标生产?";
             $("#showtable").empty();
             var arr = str.split(',');
             for (var i=0;i<arr.length-1;i++)  //最后一个数组为逗号
             {
                 var tr = $("<tr></tr>");
                 tr.append("<td width='100'>"+'<input type="hidden" name="order[]" value="'+arr[i]+'" />'+arr[i]+"</td>");
                 tr.append("<td align='left'>"+'<input type="text" name="fact_goods_day[]" id="fact_goods_day" class="width100" value="" onClick='+"WdatePicker({dateFmt:'yyyy-MM-dd'}) "+'class="width100 hasDatepicker" placeholder="日期必须填写">'+"</td>");
                 $("#showtable").append(tr);
             }
             $("#setproform").show();return false;
         } else if (status == 3) {
             var message = "是否确认标作废?";
         } else if (status == 2) {
             var message = "是否确认标完成?";
         }else if (status == 8) {
             var message = "是否确认标打款?";
         }
         else{
             return false;
         }
         if(confirm(message)){
             $.post("/batchfactoryorder/ajaxbutton", {"op": "updOrderStatus","order_id":str,"status":status},
                     function(data){
                         if(data.code==200)
                         {
                             alert(data.msg);
                             location.reload();
                         }else{
                             alert("操作失败");return false;
                         }
                         return false;
                     },"json");

         }else{
             return false;
         }
     }

 }
 //标生产必须填写日期
    function setprosubmit() {
        var status  = 1;
        var order = document.getElementsByName("order[]");
        var factory_date = document.getElementsByName("fact_goods_day[]");
        var str_order = "";
        var str_dates = "";
        for(var i=0;i<factory_date.length;i++){
            if(!factory_date[i].value){
                alert("有未填写日期的订单，请重新输入！");return false;
            }else{
                if(i==0){
                    str_order+=order[i].value;
                    str_dates+=factory_date[i].value;
                }else{
                    str_order+=","+order[i].value;
                    str_dates+=","+factory_date[i].value;
                }

            }
        }
        var message = "你确定都标生产吗?";
        if(confirm(message)){
            $.post("/batchfactoryorder/ajaxbutton", {"op": "updOrderStatus","order_id":str_order,"status":status,"str_dates":str_dates},
                    function(data){
                        if(data.code==200)
                        {
                            alert(data.msg);
                            location.reload();
                        }else{
                            alert("未知错误");return false;
                        }
                        return false;
                    },"json");

        }else{
            return false;
        }


        
    }
    function outOrderExcel() {
            $("#outexcel").val(1);
            $("#search").submit();
            $("#outexcel").val(0);
    }
</script>
<title>批量工厂订单列表</title>
<body class="withvernav">
<div class="bodywrapper">
    {{include file='/public/leftmenu.tpl'}}
    <div class="centercontent">
        <div class="pageheader notab">
            <h1 class="pagetitle">批量工厂订单列表</h1>
            <span class="pagedesc"></span>
            <div class="menulist">
                <ul class="profile_summary">
                     {{if $managers || in_array('302',$showpower)}}  <li> <a href="javascript:void(0)" onClick="savecsv()" ><span>批量导入</span></a></li>{{/if}}
                    {{if $managers || in_array('302',$showpower)}}  <li> <a href="/batchfactoryorder/addBatchOrder" target="_blank" ><span>添加</span></a></li>{{/if}}
                    
                </ul>
            </div>
        </div>
        <!--pageheader-->
        <div id="contentwrapper" class="contentwrapper">
            <div id="basicform" class="subcontent">
                <!--搜索栏-->
                <form class="stdform stdform2" method="get" id="search" action="/batchfactoryorder/batchOrderList">
                    <div>
                        <button type="button" class="btn btn_orange btn_search radius50" onclick="updOrderStatus(1);return false;">标生产</button>
                        <button type="button" class="btn btn_orange btn_search radius50" onclick="updOrderStatus(3);return false;">标作废</button>
                        <button type="button" class="btn btn_orange btn_search radius50" onclick="updOrderStatus(8);return false;">标打款</button>
                        <button type="button" class="btn btn_orange btn_search radius50" onclick="updOrderStatus(2);return false;">标完成</button>
                        <button  type="button" class="btn btn_black btn_search radius50" id="outorderexcel" onClick="outOrderExcel();return false;">导出excel</button>
                        <div class="page">{{$pageList}} 计{{$total}}条记录，共{{$totalpage}}页</div>
                    </div>
                    <div class="tableoptions">
                        工厂：
                        <select class="selectCss2" name="search_factorys" id="search_factorys" onChange="searchEmployee()">
                            <option value="">请选择</option>
                            {{foreach from=$factorys item=res key=key}}
                            <option value="{{$res.id}}" {{if $search_factorys eq {{$res.id}}}}selected{{/if}}> {{$res.name}} </option>
                            {{/foreach}}
                        </select>
                        车工：
                        <select class="selectCss2" name="search_workers" id="search_workers">
                            <option value="">请选择</option>
                            {{foreach from=$arr_workers item=res key=key}}
                                <option value="{{$res.id}}" {{if $search_workers eq {{$res.id}}}}selected{{/if}}> {{$res.name}} </option>
                            {{/foreach}}
                        </select>
                        裁剪：
                        <select class="selectCss2" name="search_caijian" id="search_caijian">
                            <option value="">请选择</option>
                            {{foreach from=$arr_caijian item=res key=key}}
                                <option value="{{$res.id}}" {{if $search_caijian eq {{$res.id}}}}selected{{/if}}> {{$res.name}} </option>
                            {{/foreach}}
                        </select>
                        生产工厂：
                        <select class="selection select2_group" name="produce_factorys" id="produce_factorys" >
                            <option value="">请选择</option>
                            {{foreach from=$produce_factorys item=res key=key}}
                            <option value="{{$res.id}}" {{if $producefactorys eq {{$res.id}}}}selected{{/if}}> {{$res.name}} </option>
                            {{/foreach}}
                        </select>
                       创建人:
                        <select name="search_creator" id="search_creator"  class="selection select2_group" style="width:120px;" >
                            <option value="" >请选择</option>
                            {{foreach from=$arr_creators item=res key=key}}
                            <option value="{{$res.id}}" {{if $search_creator eq {{$res.id}}}}selected{{/if}}>{{$res.name}} </option>
                            {{/foreach}}
                        </select>
                        <select name="search_goods" id="search_goods"  class="selection select2_group" style="width:120px;" >
                            <option value="" >查询条件</option>
                            <option value="1" {{if $search_goods eq 1}}selected{{/if}}>订单编号</option>
                            <option value="2" {{if $search_goods eq 2}}selected{{/if}}>商品编号</option>
                            <option value="3" {{if $search_goods eq 3}}selected{{/if}}>商品名称(中文)</option>
                        </select>
                        <input type="text" name="goods" id="goods" class="width200" value="{{$goods}}" placeholder="请输入查询内容" style="width:120px;"/>
                        <select name="search_status" id="search_status"  class="selection select2_group" style="width:120px;" >
                            <option value="" >状态</option>
                            <option value="4" {{if $search_status eq 4}}selected{{/if}}>新订单</option>
                            <option value="1" {{if $search_status eq 1}}selected{{/if}}>生产中</option>
                            <option value="6" {{if $search_status eq 6}}selected{{/if}}>工厂验货完成</option>
                            <option value="3" {{if $search_status eq 3}}selected{{/if}}>已作废</option>
                            <option value="2" {{if $search_status eq 2}}selected{{/if}}>已完成</option>
                        </select>
                        <select name="search_date" id="search_date"  class="selection select2_group" style="width:150px;" >
                            <option value="" >查询条件</option>
                            <option value="1" {{if $search_date eq 1}}selected{{/if}}>创建时间</option>
                            <!--
                            <option value="2" {{if $search_date eq 2}}selected{{/if}}>实际交货时间</option>
                            <option value="3" {{if $search_date eq 3}}selected{{/if}}>下单时间</option>
                            <option value="4" {{if $search_date eq 4}}selected{{/if}}>打款时间</option>
                            -->
                            <option value="3" {{if $search_date eq 3}}selected{{/if}}>下单时间</option>
                            <option value="5" {{if $search_date eq 5}}selected{{/if}}>工厂预期交货时间</option>
                        </select>
                        <input type="text"  name="starttime" value="{{$starttime}} " onClick="WdatePicker({dateFmt:'yyyy-MM-dd '})" class="width100 hasDatepicker" /> - <input type="text"  name="endtime" value="{{$endtime}} " onClick="WdatePicker({dateFmt:'yyyy-MM-dd '})" class="width100 hasDatepicker" />
                        &nbsp;
                        <input type="hidden" name="outexcel" id="outexcel" value="">
                        <button class="btn btn_orange btn_search radius50">查询</button>
                        <a href="javascript:void();" onClick="addPrint()">
                            <button class="btn btn_orange btn_search radius50">打印</button>
                        </a>&nbsp;&nbsp;&nbsp;
                        <!--
                        <button class="btn btn_orange btn_search radius50" onclick="updOrderStatus(1);return false;">
                            标生产
                        </button>
                        <button class="btn btn_orange btn_search radius50" onclick="updOrderStatus(5);return false;">标交货</button>
                        <button class="btn btn_orange btn_search radius50" onclick="updOrderStatus(3);return false;">标作废</button>
                        -->
                </form>
                    </div>

                <!--搜索栏结束-->
                <table cellpadding="0" cellspacing="0" border="0" class="stdtable">
                    <thead>
                    <tr class="lbbt">
                        <td bgcolor="#FEFFF1">
                            <a onClick="allSelect('ppid[]')">全选<input type="checkbox"></a>
                        </td>
                        <td  bgcolor="#FEFFF1">订单编号</td>
                        <td  bgcolor="#FEFFF1">所属工厂</td>
                        <td  bgcolor="#FEFFF1">生产工厂</td>
                        <td  bgcolor="#FEFFF1">仓库</td>
                        <td  bgcolor="#FEFFF1" width="5%">状态</td>
<!--                        <td  bgcolor="#FEFFF1">订单属性</td>
-->                        <td  bgcolor="#FEFFF1">商品编号</td>
                        <td  bgcolor="#FEFFF1">商品名称</td>
                        <td  bgcolor="#FEFFF1" width="10%">商品型号</td>
                        <td  bgcolor="#FEFFF1">总数量</td>
                        <td  bgcolor="#FEFFF1">工价</td>
                        <td  bgcolor="#FEFFF1">创建人<br/>创建时间</td>
                        <td  bgcolor="#FEFFF1">验收人</td>
                        <td  bgcolor="#FEFFF1" width="12%">
                            实际交货时间<br/>工厂预期交货时间<br/>客户期望交货时间<br/>
                        </td>
                    </tr>
                    </thead>
                    <tbody >

                    {{foreach from=$orderlist item=li key=key}}
                    <tr>
                        {{if ($li.days > 20 || $li.goods_days==1) && $li.order_id >20780}}
                            <td class="head0" style="background-color: red;" title="红色背景：创建日期与当前日期相差20天以上或超过客户预期交货日期">
                                <input name="ppid[]" type="checkbox" class="none" id="ppid[]" value="{{$li.order_id}}"/>
                                {{if $li.print_flag eq 1}}<img src="/fuman/images/print.png">{{/if}}
                                {{if $li.memo}}
                                <a href="javascript:void(0);" title="{{$li.memo}}"><img src="/fuman/images/bj.jpg"></a>
                                {{/if}}
                            </td>
                        {{elseif $li.days >10 && $li.order_id >20780}}
                            <td class="head0" style="background-color: orange;" title="黄色背景：创建日期与当前日期相差10天以上">
                                        <input name="ppid[]" type="checkbox" class="none" id="ppid[]" value="{{$li.order_id}}"/>
                                        {{if $li.print_flag eq 1}}<img src="/fuman/images/print.png">{{/if}}
                                        {{if $li.memo}}
                                        <a href="javascript:void(0);" title="{{$li.memo}}"><img src="/fuman/images/bj.jpg"></a>
                                        {{/if}}
                            </td>
                        {{else}}
                                <td class="head0" >
                                    <input name="ppid[]" type="checkbox" class="none" id="ppid[]" value="{{$li.order_id}}"/>
                                    {{if $li.print_flag eq 1}}<img src="/fuman/images/print.png">{{/if}}
                                    {{if $li.memo}}
                                    <a href="javascript:void(0);" title="{{$li.memo}}"><img src="/fuman/images/bj.jpg"></a>
                                    {{/if}}
                                </td>
                        {{/if}}

                        <td valign="middle"  style="position:relative;">
                               <a href="/batchfactoryorder/updBatchOrder?order_id={{$li.order_id}}" target="_blank" style="color:dodgerblue;">{{$li.order_id}}</a>
                            {{if $li.develop_id}}
                            <br/>
                            <a href="/batchfactoryorder/ajaxbutton?op=getMaterialInfo&develop_id={{$li.develop_id}}&batchorder_id={{$li.order_id}}" target="_blank">查看物料</a>
                            {{/if}}
                        </td>
                        <td valign="middle">{{if $li.factory_id==1}}工厂1{{/if}}{{if $li.factory_id==2}}工厂2{{/if}}</td>
                        <td valign="middle">{{$li.produce_factory_name}}</td>
                        <td valign="middle">
                            {{if $li.cang}}
                            {{$li.cang}}
                            {{else}}
                             1号仓
                            {{/if}}
                        </td>
                        <td valign="middle">
                            {{if $li.status eq 1}}
                            生产中
                            {{elseif $li.status eq 2}}
                            已完成
                            {{elseif $li.status eq 3}}
                            已作废
                            {{elseif $li.status eq 5}}
                            交货中
                            {{elseif $li.status eq 6}}
                            工厂验货已完成
                            {{elseif $li.status eq 7}}
                            公司验收已完成
                            {{elseif $li.status eq 8}}
                            打款中
                            {{else}}
                            新订单
                            {{/if}}

                        </td>
                      <!--  <td valign="middle">
                            {{if $li.property eq 1}}
                            批量
                            {{elseif $li.property eq 2}}
                            关联
                            {{else}}
                            {{/if}}

                        </td>-->
                        <td valign="middle">
                            {{$li.goods_code}}
                        </td>
                        <td height="58" style="position:relative;" width="10%">
                            {{$li.goods_name}}
                        </td>
                        <td width="8%">
                            {{foreach from=$li.product_alltype item=res key=key}}
                                        {{$res}}<br/>
                            {{/foreach}}
                        </td>
                        <td  valign="middle">
                            {{$li.product_totalnum}}
                        </td>
                        <td  class="cz">
                            {{$li.price}}
                        </td>
                        <td class="cz">
                            {{$li.create_user}}<br/>
                            {{$li.createtime}}<br/>
                        </td>
                        <td class="cz">
                            {{$li.accepter}}
                        </td>
                        <td class="cz">
                              <span style="color:dodgerblue;">{{$li.real_goods_date}}</span>  <br/>
                                {{$li.factory_goods_day}}<br/>
                                {{$li.goods_date}}

                        </td>
                    </tr>
                    {{/foreach}}
                    </tbody>
                </table>
                <div class="page">{{$pageList}} 计{{$total}}条记录，共{{$totalpage}}页</div>
            </div>
        </div>
        <!-- 模态框（Modal）打印内容 -->
        <form action="/factory/ajaxbutton?op=printorder"  method="post" name="attributeform" id="attributeform" target="_blank">
            <div class="modal fade" id="printform" tabindex="-1" role="dialog" aria-labelledby="sprintform" aria-hidden="true">
                <div class="modal-dialog" style="width:740px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"
                                    aria-hidden="true">× </button>
                            <h4 class="modal-title" id="sprintform"> 待处理订单编号  </h4>
                        </div>
                        <div class="modal-body">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100">订单号： </td>
                                    <td align="left"><textarea name="orderlist" id="orderlistst" cols="10" rows="10"></textarea></td>
                                </tr>

                                <tr>
                                    <td>注意： </td>
                                    <td align="left">以逗号隔开</td>
                                </tr>
                            </table>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default"
                                        data-dismiss="modal"> 关闭 </button>
                                <button type="button" class="btn btn-primary"  onclick="onstsubmit()"> 提交 </button>
                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                    <!-- /.modal-dialog -->
                </div>
            </div>
            <!-- /.modal -->
          </form>  
            
               <!-- 模态框（Modal）打印内容 -->
        <form action="/batchfactoryorder/ajaxbutton?op=savebatchexcel"  method="post" name="outcsvform" id="outcsvform" enctype="multipart/form-data">
           <div class="modal fade" id="yanwenexpressform" tabindex="-1" role="dialog" aria-labelledby="sexpressform" aria-hidden="true">
                <div class="modal-dialog" style="width:740px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal"
                                    aria-hidden="true">× </button>
                            <h4 class="modal-title" id="sprintform"> 导入Excel文档  </h4>
                        </div>
                        <div class="modal-body">
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="100">Excel： </td>
                                    <td align="left"><input type="file" name="upfile" class="width200"></td>
                                </tr>

                                <tr>
                                    <td>注意： </td>
                                    <td align="left">必须严格按照模板导入&nbsp;<a href="/fuman/Exceltemplate/FactoryOrdertemplate.xls"><font color="#0000CC">点击下载模板</font></a></td>
                                </tr>
                            </table>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default"
                                        data-dismiss="modal"> 关闭 </button>
                                <button type="button" class="btn btn-primary"  onclick="outcsvsubmit()"> 提交 </button>
                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                    <!-- /.modal-dialog -->
                </div>
            </div>
            </form>
            <!-- /.modal -->
    <!-- 模态框（Modal）标生产 -->
    <form action=""  method="post" name="setproforms" id="setproforms" enctype="multipart/form-data">
        <div class="modal fade" id="setproform" tabindex="-1" role="dialog" aria-labelledby="setproform" aria-hidden="true">
            <div class="modal-dialog" style="width:740px;margin-top: 200px;">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="$('#setproform').hide()">× </button>
                        <h4 class="modal-title" id="sprintform"> 标生产</h4>
                    </div>
                    <div class="modal-body">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="100">订单编号</td>
                                <td align="left">
                                    工厂预期交货日期
                                </td>
                            </tr>
                        </table>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" id="showtable">
                        </table>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default"
                                    data-dismiss="modal" onclick="$('#setproform').hide()"> 关闭 </button>
                            <button type="button" class="btn btn-primary"  onclick="setprosubmit()"> 提交 </button>
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>
        </div>
    </form>
    <!-- /.modal -->
</body>
</html>